import request from '@/utils/request'
import { setTokenInfo } from '@/utils/storage'
//发送验证码
export const SendCode = (mobile) => {
  return async () => {
    await request({
      url: `/sms/codes/${mobile}`,
      method: 'GET',
    })
  }
}
//保存token
export const saveToken = (tokenInfo) => {
  return { type: 'login/token', payload: tokenInfo }
}
// 登录请求
export const login = (data) => {
  return async (dispatch) => {
    const res = await request({
      method: 'POST',
      url: '/authorizations',
      data,
    })
    const tokenInfo = res.data.data
    console.log(tokenInfo)
    dispatch(saveToken(tokenInfo))
    setTokenInfo(tokenInfo)
  }
}
